package cn.flying.base.sys.configuration.shiro;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;

/**
 * @description:
 * @author: lvyong
 * @date: 2022年11月08日 15:45
 * @version: 1.0
 */
@Order(1)
@WebFilter(filterName = "authFilter", urlPatterns = "/*")
public class AuthFilter implements Filter {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 可以初始化Filter在web.xml里面配置的初始化参数
     * filter对象只会创建一次，init方法也只会执行一次。
     * @param filterConfig
     * @throws ServletException
     */
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
//        logger.info("登录过滤器初始化！！！");
    }

    /**
     * 主要的业务代码编写方法
     * @param servletRequest
     * @param servletResponse
     * @param filterChain
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        logger.info("执行是否登录拦截校验！！！");
//        HttpServletRequest request = (HttpServletRequest) servletRequest;
//        HttpServletResponse response = (HttpServletResponse) servletResponse;
//        System.out.println(request.getRequestURI());
//        System.out.println(request.getParameter("Access_Token"));
        filterChain.doFilter(servletRequest, servletResponse);
    }

    /**
     * 在销毁Filter时自动调用。
     */
    @Override
    public void destroy() {
//        logger.info("登录过滤器销毁！！！");
    }
}
